﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace GSManager
{
    public class TonKho
    {
        private int _STT;
        private string _MaSanPham;
        private int _SoLuongBan;
        private int _SoLuongMua;
        public int STT
        {
            get { return _STT; }
            set { _STT = value; }
        }
        public string MaSanPham
        {
            get { return _MaSanPham; }
            set { _MaSanPham = value; }
        }
        public int SoLuongBan
        {
            get { return _SoLuongBan; }
            set { _SoLuongBan = value; }
        }
        public int SoLuongMua
        {
            get { return _SoLuongMua; }
            set { _SoLuongMua = value; }
        }
        public void Luu()
        {
            OleDbConnection ketnoi = KetNoi.KetNoiDuLieu();
            string sql = "select Max(STT) from TONKHO";
            OleDbCommand cmd = new OleDbCommand(sql, ketnoi);
            OleDbDataReader r = cmd.ExecuteReader();
            while (r.Read())
            {
                try
                {
                    STT = (int)r[0];
                    STT++;
                }
                catch (Exception) { STT = 1; }
            }
            r.Close();
            sql = "insert into TONKHO values(" + STT + ",'" + MaSanPham + "'," + SoLuongBan + "," + SoLuongMua + ")";
            cmd = new OleDbCommand(sql, ketnoi);
            cmd.ExecuteNonQuery();
            ketnoi.Close();
        }
    }
}
